use windows::Win32::{
	Foundation::*,
	Graphics::Gdi::InvalidateRect,
	UI::WindowsAndMessaging::{CloseWindow, GetClientRect, ShowWindow, SW_SHOW},
};

use super::Window;

#[derive(Clone, Copy)]
pub struct WinRef<'a>(pub &'a HWND);
impl<'a> types::WinRef<WinRaw> for WinRef<'a> {
	fn raw(&self) -> Option<WinRaw> {
		return Some(WinRaw::from(self.0 .0));
	}
	fn show(&self) {
		_ = unsafe { ShowWindow(*self.0, SW_SHOW) };
	}
	fn close(&self) {
		_ = unsafe { CloseWindow(*self.0) };
	}
	fn fresh(&self, _: &str) {
		_ = unsafe { InvalidateRect(*self.0, None, FALSE) };
	}
	fn size(&self) -> (u32, u32) {
		let mut rect = RECT::default();
		_ = unsafe { GetClientRect(*self.0, &mut rect) };
		((rect.right - rect.left).max(0) as _, (rect.bottom - rect.top).max(0) as _)
	}
	fn density(&self) -> f32 {
		// TODO
		1.
	}
}

#[derive(Debug)]
pub struct WinHandle(pub HWND);
impl types::WinHandle<Window> for WinHandle {
	fn with(&self, fun: impl FnOnce(WinRef<'_>)) {
		fun(WinRef(&self.0));
	}
}

mod win;
pub use win::*;

mod raw;
pub use raw::*;

mod event;
pub use event::*;
